package drivers

import "gorm.io/gorm"

type GormQueryInterface interface {
	SetDB(db *gorm.DB)
	Paginate(page, size int) *gorm.DB
}

type GormQuery struct {
	db *gorm.DB
}

func (i *GormQuery) SetDB(db *gorm.DB) {
	i.db = db
}

func (i *GormQuery) Paginate(page, size int) *gorm.DB {
	if page < 1 {
		page = 1
	}
	if size < 1 {
		size = 10
	}
	offset := (page - 1) * size
	return i.db.Limit(size).Offset(offset)
}
